package com.yoomiito.app.present.my.fragment;

import com.yoomiito.app.Constant;
import com.yoomiito.app.model.my.MyMonthOrderInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.my.MyMonthOrderFragment;
import com.yoomiito.app.utils.NetworkUtils;
import com.yoomiito.app.utils.YMToast;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

@Deprecated
public class MyMonthOrderFmPresenter extends XPresent<MyMonthOrderFragment> {

    /**
     * 老接口 废除
     * @param page
     * @param month
     */
    public void getMonthOrderData(int page,int month){
        if (NetworkUtils.checkNetPermission(getV().getContext())){
            getV().finishReferesh();
            return;
        }
        YmApi.getYmService()
                .getMonthOrder(page,month,Constant.PAGE_SIZE)
                .compose(getV().bindToLifecycle())
                .compose(XApi.<MyMonthOrderInfo>getApiTransformerData())
                .compose(XApi.<MyMonthOrderInfo>getScheduler())
                .subscribe(new ApiSubscriber<MyMonthOrderInfo>() {
                    @Override
                    public void onSuccess(MyMonthOrderInfo data) {
                        getV().setMonthOrderData(data);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        YMToast.showText("error");
                    }
                });
    }

    public void getData(int page,int month){
        YmApi.getYmService()
                .getMonthOrder_2(page,Constant.PAGE_SIZE)
                .compose(getV().bindToLifecycle())
                .compose(XApi.<MyMonthOrderInfo>getApiTransformerData())
                .compose(XApi.<MyMonthOrderInfo>getScheduler())
                .subscribe(new ApiSubscriber<MyMonthOrderInfo>() {
                    @Override
                    public void onSuccess(MyMonthOrderInfo data) {
                        getV().setMonthOrderData(data);
                    }

                    @Override
                    public void onFail(ApiException error) {
                        YMToast.showText("error");
                        getV().dismissLoading();
                    }
                });
    }
}
